<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>parse_player_data (GamedayParser)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File lib/gameday_parser.rb, line 8</span>
        <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse_player_data</span>(<span class="ruby-identifier">doc</span>, <span class="ruby-identifier">team</span>, <span class="ruby-identifier">logger</span>)
                <span class="ruby-identifier">updated_player_count</span> = <span class="ruby-value">0</span>
                <span class="ruby-identifier">new_player_count</span> = <span class="ruby-value">0</span>
                <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">each_element</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">player</span><span class="ruby-operator">|</span>
                        <span class="ruby-identifier">gameday_id</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'id'</span>]
                        <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">gameday_id</span>)
                                <span class="ruby-identifier">old_player</span> = <span class="ruby-constant">Player</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>, <span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">'gameday_id='</span><span class="ruby-operator">+</span><span class="ruby-identifier">gameday_id</span>)
                                <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">old_player</span>
                                        <span class="ruby-comment cmt"># update player    </span>
                                        <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">first_name</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'first'</span>]
                                        <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">last_name</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'last'</span>]
                                        <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">position</span> = <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'pos'</span>]
                                        <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">team_id</span> = <span class="ruby-identifier">team</span>.<span class="ruby-identifier">id</span>
                                        <span class="ruby-identifier">old_player</span>.<span class="ruby-identifier">save</span>
                                        <span class="ruby-identifier">updated_player_count</span> = <span class="ruby-identifier">updated_player_count</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>
                                <span class="ruby-keyword kw">else</span>
                                        <span class="ruby-comment cmt"># create player    </span>
                                        <span class="ruby-constant">Player</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">:gameday_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">gameday_id</span>, 
                                                                  <span class="ruby-identifier">:first_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'first'</span>], 
                                                                  <span class="ruby-identifier">:last_name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'last'</span>], 
                                                                  <span class="ruby-identifier">:position</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">player</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'pos'</span>], 
                                                                  <span class="ruby-identifier">:team_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">team</span>.<span class="ruby-identifier">id</span>)
                                        <span class="ruby-identifier">new_player_count</span> = <span class="ruby-identifier">new_player_count</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>
                                <span class="ruby-keyword kw">end</span>
                        <span class="ruby-keyword kw">end</span>
                <span class="ruby-keyword kw">end</span>   
                <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Team: #{team.name}&quot;</span>
                <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Updated Players: #{updated_player_count}&quot;</span>
                <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;New Players: #{new_player_count}&quot;</span>
                <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Completed #{team.name}&quot;</span>
        <span class="ruby-keyword kw">end</span></pre>
</body>
</html>